package demo1;

public class Test {
    public static void main(String[] args) {
        List<Integer> linkedList = new LinkedList<>();
        linkedList.add(10);
        linkedList.add(20);
        linkedList.add(30);
        //遍历链表-方式1
        System.out.println(linkedList);
        //方式2
        for (int x:linkedList) {
            System.out.print(x+" ");
        }
        System.out.println();
        //方式3-->使用迭代器-->正向迭代
        ListIterator lit = linkedList.listIterator();
        while (lit.hasNext()){
            System.out.print(lit.next()+" ");
            lit.remove();//边遍历边删除
        }
        System.out.println();
        //方式4-->使用迭代器-->反向迭代
        ListIterator lit2 = linkedList.listIterator(linkedList.size());
        while (lit2.hasPrevious()){
            System.out.print(lit2.previous()+" ");
        }
        System.out.println();
    }
    public static void main1(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();
        myLinkedList.addFirst(30);
        myLinkedList.addFirst(30);
        myLinkedList.addFirst(30);
        myLinkedList.addFirst(40);
        myLinkedList.display();
        myLinkedList.addLast(50);
        myLinkedList.display();
        myLinkedList.addIndex(0,9);
        myLinkedList.display();
        myLinkedList.addIndex(myLinkedList.size(), 60);
        myLinkedList.display();
        myLinkedList.addIndex(2,35);
        myLinkedList.display();
        myLinkedList.remove(30);
        myLinkedList.display();
        myLinkedList.removeAllKey(30);
        myLinkedList.display();
    }
}
